﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Web.UI;
using System.Web.UI.WebControls;
using System.Data.SqlClient;

public partial class XY_add_select_course : System.Web.UI.Page
{
    protected void Page_Load(object sender, EventArgs e)
    {

    }
    protected void GridView1_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox1.Text = GridView1.SelectedRow.Cells[0].Text;
        TextBox2.Text = GridView1.SelectedRow.Cells[1].Text;
    }
    protected void GridView2_SelectedIndexChanged(object sender, EventArgs e)
    {
        TextBox3.Text = GridView2.SelectedRow.Cells[0].Text;
        TextBox4.Text = GridView2.SelectedRow.Cells[1].Text;
    }
    protected void Button1_Click(object sender, EventArgs e)
    {
        string conn = "Data Source= . ;Initial Catalog=XSXK; User ID=sa; pwd=123";
        SqlConnection connection = new SqlConnection(conn);
        try
        {
            connection.Open();
            SqlCommand comm = new SqlCommand();
            comm.Connection = connection;

            string str_sql = " insert into Select_course(Sno,Cno) values('"+TextBox1.Text+"','"+TextBox3.Text+"') ";
            comm.CommandText = str_sql;

            comm.ExecuteNonQuery();
            Response.Write("<h1>成功添加学生选课信息!</h1>");


        }
        catch (SqlException ex)
        {
            Response.Write(ex.Message);
        }

        finally
        {
            connection.Close();//关闭数据库连接
        }
    }
}